package com.fz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.entity.TRole;
import com.fz.service.TRoleService;
import com.fz.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author wangyi
 * @since 2024-08-15
 */
@RestController
@RequestMapping("/tRole")
public class TRoleController {
    @Resource
    TRoleService tRoleService;
    @GetMapping("/list")
    ResultVo<IPage<TRole>> list(Integer PageNo, Integer PageSize)throws InterruptedException {

        return ResultVo.success(tRoleService.page(new Page<>(PageNo,PageSize)));
    }
    @PostMapping("/add")
    ResultVo<Boolean> addTRole(String name,String description,String permission) {
        return ResultVo.success(tRoleService.add(name,description,permission),"添加角色成功");
    }
    @GetMapping("/getById")
    ResultVo<TRole> getById(long id){
        return ResultVo.success(tRoleService.getById(id));
    }
    @PostMapping("/update")
    ResultVo<Boolean> updateTRole(long id, String name,String description,String permission) {
        return ResultVo.success(tRoleService.update(id,name,description,permission),"修改成功");
    }
    @PostMapping("/del")
    ResultVo<Boolean> deleteTRole(Long id,Boolean status) {
        return ResultVo.success(tRoleService.del(id,status),status ? "启用角色成功" : "禁用角色成功");
    }
}
